﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //1、生成一个随机整型数组，长度是10，内容是1~10，数组内容不重复。

            Console.WriteLine("1、生成一个随机整型数组，长度是10，内容是1~10，数组内容不重复\n");
            int Number = 10;
            int minNum = 1;
            int maxNum = 10;

            foreach (int num in GetRandomArray(Number, minNum, maxNum))
            {
                Console.Write(" " + num + " |");
            }

            Console.WriteLine();

            //2、生成0 - 5之间的随机小数，保留两位小数。

            Console.WriteLine("\n2、生成0 - 5之间的随机小数，保留两位小数。\n");
            Random ran = new Random();
            double a = ran.Next(5);
            double b = ran.NextDouble();
            Console.WriteLine("\t\t|" + (a + b).ToString("f2")+"|");

            //3、生成4 - 7之间的随机小数，保留两位小数。

            Console.WriteLine("\n3、生成4 - 7之间的随机小数，保留两位小数。\n");
            double c = ran.Next(4,7);
            double d = ran.NextDouble();
            Console.WriteLine("\t\t|" + (c + d).ToString("f2")+"|");

            //4、用户输入邮箱，请验证其合法性。

            Console.WriteLine("\n4、用户输入邮箱，请验证其合法性;\n5、用户输入手机号码，请验证其合法性。\n");
            while (true)
            {

                Console.WriteLine("请输入邮政编码：");
                string email = Console.ReadLine();
                Regex regex = new Regex(@"^(\w){6，}+@(\w\.){1}(\w\.)*(com){1}|(cn){1}|(net){1}|$");

                if (regex.IsMatch(email))
                {
                    Console.WriteLine("给定的{0}是合法的邮政编码！", email);
                }
                else
                {
                    Console.WriteLine("给定的{0}邮箱不合法！", email);
                }

                Console.WriteLine("请输入手机号码：");
                string phonenumber = Console.ReadLine();

                Regex regex1 = new Regex(@"^\+86135|\+86159|\+86180|\+86183|\+86189|\+86157|\+86177|\+86130\d{8}");

                if (regex1.IsMatch(phonenumber))
                {
                    Console.WriteLine("给定的{0}是合法的手机号码！", phonenumber);
                }
                else
                {
                    Console.WriteLine("给定的{0}手机号码不合法！", phonenumber);
                }
                Console.ReadKey();
            }
        }
        // Number随机数个数
        // minNum随机数下限
        // maxNum随机数上限
        public static int[] GetRandomArray(int Number, int minNum, int maxNum)
        {
            int i;
            int ranNum;
            int Num;
            int[] arr = new int[Number];
            Random r = new Random();


            for (i = 0; i < Number; i++)
            {
                ranNum = r.Next(minNum, maxNum + 1);
                Num = 0;

                for (int j = 0; j < i; j++)
                {
                    if (arr[j] == ranNum)
                    {
                        Num++;
                    }
                }
                if (Num == 0)
                {
                    arr[i] = ranNum;
                }
                else
                {
                    i--;
                }
            }
            return arr;
        }
    }
}

